package com.project.slsx.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lzy.okgo.model.HttpParams;
import com.project.slsx.R;
import com.project.slsx.bean.PurchaseResultBean;
import com.project.slsx.utils.GlideUtils;
import com.project.slsx.utils.ParamsUtils;

import org.angmarch.views.NiceSpinner;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

public class PurchaseResultAdapter extends BaseQuickAdapter<PurchaseResultBean.ResultBean, BaseViewHolder> {

    public PurchaseResultAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder holder, PurchaseResultBean.ResultBean item) {
        RequestOptions option = GlideUtils.getOption();
        ImageView thumb = holder.getView(R.id.iv_purchase);
        Glide.with(mContext).load(item.getThumb()).apply(option).into(thumb);
        holder.setText(R.id.tv_purchase_title, item.getTitle());
        holder.setText(R.id.tv_purchase_total, item.getTotal());
        holder.setText(R.id.tv_purchase_day, item.getDay() + "");
        NiceSpinner spinner = holder.getView(R.id.nicespinner);
        List<PurchaseResultBean.ResultBean.SupplierBean> supplier = item.getSupplier();
        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < supplier.size(); i++) {
            strings.add(supplier.get(i).getName());
        }
        spinner.attachDataSource(strings);

        holder.getView(R.id.btn_minus).setOnClickListener(v -> {
            //采购编辑 减
            if (onItemEditListener != null) {
                onItemEditListener.onItemEditListener(item,holder.getLayoutPosition(), false);
            }
        });

        holder.getView(R.id.btn_plus).setOnClickListener(v -> {
            //采购编辑 加
            if (onItemEditListener != null) {
                onItemEditListener.onItemEditListener(item, holder.getLayoutPosition(), true);
            }
        });
    }

    public interface OnItemEditListener {
        void onItemEditListener(PurchaseResultBean.ResultBean item, int position, boolean b);
    }

    private OnItemEditListener onItemEditListener;

    public void setOnItemEditListener(OnItemEditListener onItemEditListener) {
        this.onItemEditListener = onItemEditListener;
    }
}
